// webpack配置相关
const webpack = require('webpack')
const webpackDevMiddleware = require('webpack-dev-middleware')
const webpackHotMiddleware = require('webpack-hot-middleware')
const config = require('@vue/cli-service/webpack.config.js')
const compiler = webpack(config)

// express服务器
const express = require('express')
const app = express()

// 解决历史路由配置
let history = require('connect-history-api-fallback')
app.use(history())

// 系统监控模块
const osUtils = require('./utils/os-utils')

// express中间件服务器
app.use(webpackDevMiddleware(compiler,{
    publicPath: config.output.publicPath,
    stats: { colors: true },
}))

// 热重载中间件
app.use(webpackHotMiddleware(compiler))

// 代理转发路由
app.get('/os',(req, res)=>{
    new osUtils().getOsInfo((e)=>{
        res.send(e)
    })
})

// express监听
app.listen(5000, () => {
    console.log(`Example app listening on port ${5000}`)
})